package UIFree.controls
{
	import UIFree.uif_component;
	import UIFree.uif_ecomponent;
	
	import flash.events.Event;
	import flash.events.MouseEvent;


	public class uif_hotspotButton extends uif_baseCheckBox {
		private var _hotspot: uif_ecomponent;
		public function uif_hotspotButton(parent:uif_component, ax:int=0, ay:int=0, awidth:int=0, aheight:int=0, styleClass: Object='') {
			super(parent, ax, ay, awidth, aheight, styleClass);
			_hotspot = createHotspot();
			applyChildStyle('hotspot');
			asButton();
			if (style.hasOwnProperty(uif_component.FIELD_FOCUSSTYLE)) {
				addEvent(MouseEvent.ROLL_OVER, doRollOver);
				addEvent(MouseEvent.ROLL_OUT, doRestoreStyle);
			}
			if (style.hasOwnProperty('downStyle')) {
				addEvent(MouseEvent.MOUSE_DOWN, doMDown);
				addEvent(MouseEvent.MOUSE_UP, doMUp);
			}
		}
		
		protected function createHotspot(): uif_ecomponent {
			return null;
		}
		
		protected function doRollOver(e: MouseEvent): void {
			if (!disable && !e.buttonDown) {
				styleFX(style, app.styleByObj(style[uif_component.FIELD_FOCUSSTYLE])).start();
				if (parent && group) parent.swapChildren(this, parent.getChildAt(parent.numChildren - 1));
			}
		}
		
		protected function doMDown(e: MouseEvent): void {
			if (!disable) styleFX(style, app.styleByObj(style['downStyle'])).start();
		}
		
		protected function doRestoreStyle(e: MouseEvent=null): void {
			if (!disable) styleFX(style, app.styleByObj(
				(style.hasOwnProperty('checkedStyle')&&checked)?style['checkedStyle']:styleClass
			)).start();
		}
		
		protected function doMUp(e: MouseEvent): void {
			if (!disable) styleFX(style, app.styleByObj(style[uif_component.FIELD_FOCUSSTYLE])).start();
		}
		
		public function get hotspot(): uif_ecomponent {
			return _hotspot;
		}
		
		override protected function doDisable(a_set: Boolean): void {
			doRestoreStyle();
			super.doDisable(a_set);
		}
		
		protected function refreshStyleChecked(): void {
			if (style.hasOwnProperty('checkedStyle')) {
				styleFX(style, app.styleByObj(checked?style['checkedStyle']:styleClass)).start();
			}
		}
		
		override protected function changeChecked(a_checked: Boolean): void {
			if (!disable) {
				super.changeChecked(a_checked);
				refreshStyleChecked();
			}
		}		
		
	}
}